package com.jp.knowledge.dialog;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jiayen.util.ToasUtil;
import com.jp.knowledge.R;

/**
 * Created by jiayen on 16/10/10.
 * 删除头条理由
 */
public class DelToutiaoSelectPopuWindow extends PopupWindow implements View.OnClickListener {
    private View conentView;

    private Context mContext;

    private TextView old;//太旧
    private TextView bad;//太差
    private TextView looked;//看过了
    private TextView notLike;//不喜欢
    public DelToutiaoSelectPopuWindow(final Activity context) {
        this.mContext = context;
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        conentView = inflater.inflate(R.layout.toutiao_select_dialog, null);
        int h = context.getWindowManager().getDefaultDisplay().getHeight();
        int w = context.getWindowManager().getDefaultDisplay().getWidth();
        // 设置SelectPicPopupWindow的View
        this.setContentView(conentView);
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(RelativeLayout.LayoutParams.MATCH_PARENT);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        // 刷新状态
        this.update();
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0000000000);
        // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ，设置其他控件变化等操作
        this.setBackgroundDrawable(dw);
         this.setAnimationStyle(android.R.style.Animation_Dialog);

        init();
    }

    private void init(){
        conentView.findViewById(R.id.old_btn).setOnClickListener(this);
        conentView.findViewById(R.id.bad_btn).setOnClickListener(this);
        conentView.findViewById(R.id.looked_btn).setOnClickListener(this);
        conentView.findViewById(R.id.not_like_btn).setOnClickListener(this);
    }

    /**
     * 显示popupWindow
     *
     * @param parent
     */
    public void showPopupWindow(View parent) {
        if (!this.isShowing()) {
            // 以下拉方式显示popupwindow
            this.showAsDropDown(parent, parent.getLayoutParams().width / 2, 18);
        } else {
            this.dismiss();
        }
    }

    @Override
    public void onClick(View view) {
            switch (view.getId()){
                case  R.id.old_btn:

                    break;
                case  R.id.bad_btn:

                    break;
                case  R.id.looked_btn:

                    break;
                case  R.id.not_like_btn:

                    break;
                default:
                    break;
            }
    }

    private void handDel(int reslut){
        ToasUtil.toast(mContext, "原因"+reslut);
    }
}
